<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <#include "/pubHeadStyleTree.html">
</head>
<body>
<div class="layui-collapse" style="margin: 15px;">
    <form lay-filter="nodeMessageForm" id="nodeMessageForm">
        <table class="layui-table">
            <tr>
                <th>发送：</th>
                <td>
                    <input type="checkbox" id="sendInner" value="1" name="sendInner" lay-skin="primary" <#if innerMessage.isSend == 1>checked="checked"</#if>>
                </td>
            </tr>
            <tr>
                <th>消息主题：</th>
                <td>
                    <input type="text" id="subject_inner" name="subject_inner" class="layui-input" value="${innerMessage.subject}" style="width: 70%">
                </td>
            </tr>
            <tr>
                <th>消息接收人：</th>
                <td>
                    <!--<input style="width: 84.5%!important;float: left" rtype="6" type="text" id="receiver_inner" name="receiver_inner" value='${receiverInnerCondJsons}'readonly="readonly" class="layui-input token-input">-->
                    <div style="width: 84.5%!important;float: left;line-height: 38px;height: auto;min-height: 38px;" rtype="6" type="text" id="receiver_inner" name="receiver_inner" value='${receiverInnerCondJsons}' readonly="readonly" class="layui-input token-input">
                    </div>
                    <!--<div class="layui-input token-input" style="width: 84.5%!important;float: left" rtype="6" type="text" id="receiver_inner" name="receiver_inner"></div>-->
                    <div style="margin-top: 10px">
                        <a class="iconfont iconicon_setting" id="selectReceiveUser">设置</a>
                    </div>
                </td>
            </tr>
            <tr>
                <th>消息模板</th>
                <td>
                    <div>
                        <!--<span class="commonScript" style="cursor: pointer;">-->
                            <!--<i class="layui-icon layui-icon-fonts-code"></i>常用脚本-->
                        <!--</span>-->
                        &nbsp;
                        表单变量:
                        <select name="flowVars" class="flowVars">
                            <option value="">请选择</option>
                        </select>
                    </div>
                    <textarea  id="template_inner" name="template_inner" codemirror="true" style="display: none;" mirrorheight="200px" rows="10" cols="80"  >
                        ${innerMessage.template}
                    </textarea>
                </td>
            </tr>
        </table>
        <input type="hidden" id="id" name="id" value="${id}"  class="inputText"/>
        <input type="hidden" id="procDefId" name="procDefId" value="${procDefId}"  />
        <input type="hidden" id="nodeId" name="nodeId" value="${nodeId}" />
        <input type="hidden" id="modelId" name="modelId" value="${modelId}" />
        <input type="hidden" id="mailMessageId" name="mailMessageId" value="${mailMessage.id}"/>
        <input type="hidden" id="innerMessageId" name="innerMessageId" value="${innerMessage.id}"  />
        <input type="hidden" id="smsMessageId" name="smsMessageId" value="${smsMessage.id}"  />
    </form>
</div>
<div style="text-align: center;margin-top: 10px;position: absolute;bottom: 15px;width:100%;">
    <button class="layui-btn save">保存</button>
    <button class="layui-btn cancelFrom layui-btn-danger">取消</button>
</div>
<style>
.messageRecipients i{
font-style: normal;
    }
.messageRecipients i.layui-icon-close{
    cursor: pointer;
}
.messageRecipients{
    display: inline-block;
    line-height: 12px;
    padding: 5px 10px;
    margin-right: 5px;
    background: rgba(8,157,213,0.3);
    border: 1px solid #0b73df;
}
</style>
<script>
    layui.config({
        base: serverPath.systemPath + staticPath.systemPath //静态资源所在路径
    }).extend({
        index: 'index' //主入口模块
    }).use(['index','table', 'layer', 'jquery', 'form', 'commons','element', 'setter', 'layedit', 'common'], function () {
        var table = layui.table,
            layer = layui.layer,
            $ = layui.jquery,
            element = layui.element,
            setter = layui.setter,
            commons = layui.commons,
            layedit = layui.layedit,
            form = layui.form;

        var procDefId = '${procDefId}';
        var nodeId = '${nodeId}';
        var receiverInnerCondJsons = ${receiverInnerCondJsons};
        var editIndex = layedit.build('template_inner');
        //消息接收人回显
        if (receiverInnerCondJsons){
            $.each(receiverInnerCondJsons,function (k,v) {
                var htmls = '<span class="messageRecipients"><i>批次号['+v.groupNo+']-'+v.conditionShow+'</i><i value='+v.id+' class="layui-icon layui-icon-close"></i></span>';
                $("#receiver_inner").append(htmls);
            });
            deledeMessage();
        }
        $(".cancelFrom").click(function(){
            parent.layer.close(parent.layer.getFrameIndex(window.name));
        });
        $(".save").click(function () {
            layedit.sync(editIndex);
            $.ajax({
                type: "post",
                dataType: "json",
                data: $("#nodeMessageForm").serialize(),
                url: serverPath.workflowPath + "/workflow/bpmNodeMessage/save",
                success: function (result) {
                    if (commons._filterRecord(result)) {
                        window.parent.layer.alert(result.msg, function (thisIndex) {
                            parent.layer.close(thisIndex);
                            parent.layer.close(parent.layer.getFrameIndex(window.name));
                        });
                    } else {
                        window.parent.layer.alert(result.msg);
                    }
                }
            });

        });

        $("#selectReceiveUser").on('click',function () {
            var type = 6;
            parent.layer.open({
                type: 2,
                title: "选择接收人员",
                shade: 0.3,
                area: ['900px', '650px'],
                content: serverPath.workflowPath + setter.workflowLinkPath + 'bpmNodeMessage/receiverSetting?procDefId='+ procDefId + '&nodeId=' + nodeId + "&type=" + type,
                end: function () {
                    reloadToken(type);
                }
            });
        });

        function reloadToken(type){
            var url = "${ctx}/workflow/bpmNodeMessage/getReceiverUserCondition";
            var param = {
                procDefId:procDefId,
                nodeId:nodeId,
                receiverType:type
            };

            var tokenContainer = $(".token-input[rtype="+type+"]");

            $.ajax({
                type: "post",
                url: url,
                dataType:"json",
                data:param,
                success:function (result) {
                    if (commons._filterRecord(result)) {
                        $("#receiver_inner").empty();
                        for (var i=0;i<result.data.length;i++){
                            var id = result.data[i].id;
                            var groupNo = result.data[i].groupNo;
                            var name = result.data[i].conditionShow;
                            var htmls = '<span class="messageRecipients"><i>批次号['+groupNo+']-'+name+'</i><i value='+id+' class="layui-icon layui-icon-close"></i></span>'
                            $("#receiver_inner").append(htmls)
                        }
                        deledeMessage();
                    }else{
                        layer.alert(data.msg);
                    }
                }
            });
        }
function deledeMessage() {
    $('.messageRecipients i.layui-icon-close').click(function () {
        var conditionId = $(this).attr('value'),
            thet = $(this)
        layer.confirm('确定删除吗？',{title:'提示'}, function(index) {
            $.ajax({
                type: "post",
                dataType: "json",
                url: serverPath.workflowPath + "/workflow/bpmUserCondition/del",
                data:{conditionIds:conditionId},
                success: function (data) {
                    thet.parent().remove();
                    layer.close(index);
                    layer.msg('删除成功',{icon:1})
                }
            });


        });
    })
}
        function getTokensFromConditions(conds){
            var tokenData=[];
            for (var i=0;i<=conds.length;i++){
                var id = conds[i].id;
                var groupNo = conds[i].groupNo;
                var name = conds[i].conditionShow;
            }
            $.each(conds, function (index, item) {

                var id = item.id;
                var name = "批次号["+item.groupNo+"] - "+item.conditionShow;
                tokenData.push({id:id,name:name});

            });
            return tokenData;
        }

        $(".close").click(function () {
            parent.layer.close(parent.layer.getFrameIndex(window.name));
        });

    });
</script>
<script type="text/javascript" src="${ctx}/workflowStatic/js/flowVars.js"></script>
</body>
</html>